package com.sykj.manage.web;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.sykj.manage.service.BUsinessOrService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.model.BisCustomUser;
import com.sykj.manage.model.BisNurseType;
import com.sykj.manage.model.Biswechatrecord;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;

@Controller
@RequestMapping("/manage")
public class YangController {
	@Autowired 
	BUsinessOrService service;
	
	
	
	//显示
	@RequestMapping("/weixinGetAll")
	@ResponseBody
	public ManageBody weixinGetAll(Biswechatrecord biswe,Integer offset,Integer pageSize){
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize), pageSize==null?10:pageSize, true);
		List<Biswechatrecord> weixin = service.weixinGetAll(biswe);
		PageInfo<Biswechatrecord> pageInfo = new PageInfo<Biswechatrecord>(weixin);
		return ManageBody.getData((int)pageInfo.getTotal(), pageInfo.getList(), "");
	}
	
	
	
	//选择用户
	@RequestMapping("seleCustUser")
	@ResponseBody
	public Object seleCustUser(){
		List<BisCustomUser> custUserGetAll = service.custUserGetAll();
		return custUserGetAll;
	}
	
	//循环添加
	@RequestMapping("addWechatRecord")
	@ResponseBody
	public Object addWechatRecord(Biswechatrecord biswechatrecord) throws IllegalAccessException, InvocationTargetException{
		String[] names = biswechatrecord.getSend_user_id().split(",");
		int addWechatRecord = 0;
		biswechatrecord.setCreate_time(new Date());
		biswechatrecord.setSend_time(new Date());
		for (String name: names) {
			String replace = UUID.randomUUID().toString().replace("-", "");
			biswechatrecord.setRecord_id(replace);
			Biswechatrecord biswechatrecord2 = new Biswechatrecord();
			ConvertUtils.register(new DateConverter(null), java.util.Date.class);
			BeanUtils.copyProperties(biswechatrecord2, biswechatrecord);
			biswechatrecord2.setSend_user_id(name);
			addWechatRecord = service.addWechatRecord(biswechatrecord2);
		}
		return addWechatRecord;
	}
	
	//删除
	@RequestMapping("delewechatrecord/{id}")
	@ResponseBody
	public Object delewechatrecord(@PathVariable("id") String id){
		int delewechatrecord = service.delewechatrecord(id);
		return delewechatrecord;
	}

	
	
	
	
	
}